// 测评
<template>
  <div class="app-container">
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog
      title="发起测评"
      :visible.sync="open"
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="10">
            <el-form-item label="测试人员:" prop="schoolIds">
              <el-input
                v-model="pupilProfile.schoolName"
               :disabled="displays"
                type="text"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
           <el-input
                v-model="pupilProfile.className"
                   :disabled="displays"
                type="text"
              />
          </el-col>
          <el-col :span="6">
           <el-input
                v-model="pupilProfile.studentName"
                   :disabled="displays"
                type="text"
              />
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="24">
            <el-form-item label="测评名称：" prop="name">
              <el-input v-model="form.name" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="采用量表" prop="formId">
              <el-select
                v-model="form.formId"
                clearable
                placeholder="请选择量表"
                @change="handleChange"
              >
                <el-option
                  v-for="item in scaleList"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="量表类型:">
              <div>{{ objMatter.categoryDictText }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="适应对象:">
              <div>{{ objMatter.typeDictText }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测评时间段:" prop="startDate">
              <el-date-picker
                v-model="dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="测试时长:" prop="duration">
              <el-input
                v-model="pupilProfile.duration"
                placeholder="请输入测试时长"
                clearable
                type="number"
                min="0"
              >
                <template slot="append">分钟</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input
                v-model="pupilProfile.remark"
                type="textarea"
                placeholder="请输入内容"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">发 布</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  schoolPage, //获取学校
  classPull, //年级列表
  studentPage, //获取学生信息
} from "@/api/information/index";

import {
  formcfgList, //量表列表
  settingSaveOrUpdate, //发起测评
} from "@/api/itemBank/index";

export default {
  name: "User",
  dicts: [
    "sys_normal_disable",
    "sys_user_sex",
    "suitable_object",
    "measure_status",
  ],
  props: {
    // 学生参数
    pupilProfile: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      // 是否显示弹出层
      open: false,
      dateRange: [],
      schoolList: [],
      classList: [],
      studentList: [],
      // 量表选项
      scaleList: [],
      displays: true,
      objMatter: {},
      // 表单参数
      form: { classIds: [], schoolIds: null, studentIds: [] },
      // 表单校验
      rules: {
        name: [{ required: true, message: "请输入测评名称", trigger: "blur" }],
        formId: [{ required: true, message: "请选择量表", trigger: "blur" }],
        schoolIds: [
          { required: true, message: "请选择测评人员", trigger: "blur" },
        ],
        duration: [
          {
            required: true,
            message: "请输入测评时长",
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {},
  created() {
        this.reset()
    this.getNormalScale();
    this.getScaleType();

  },
  methods: {
    // 获取正常量表
    getNormalScale() {
      // usingStatus: 0 //启用状态
      formcfgList({ usingStatus: 0, examType:1 }).then((response) => {
        this.scaleList = response.rows;
      });
    },
   
    handleChange(val) {
      this.scaleList.forEach((item) => {
        if (item.id === val) {
          this.objMatter = item;
          console.log("KKK", item);
        }
      });
    },
    muchChange(value) {
      if (value) {
        this.queryParams.category = value[value.length - 1];
      }
    },
    /** 提交按钮 */
    submitForm: function () {
      this.form.startDate = this.dateRange[0]
        this.form.endDate = this.dateRange[1]
        this.form.measureType = "2" //个测
      this.form.type = this.objMatter.type;
       this.form.schoolIds=this.pupilProfile.schoolIds
      this.form.category = this.objMatter.category;
      this.form.classIds.push(this.pupilProfile.classid);
      this.form.studentIds.push(this.pupilProfile.studentid);
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.userId != undefined) {
            updateUser(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
            });
          } else {
            settingSaveOrUpdate(this.pupilProfile).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
            });
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        classIds: [],
        schoolIds: null,
        studentIds: [],
      };

      this.dateRange = [];
      this.objMatter = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      (this.queryParams.startDate = this.dateRange1[0]),
        (this.queryParams.endDate = this.dateRange1[1]),
        (this.queryParams.pageNum = 1);
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
